package xzy.Controller;

import lombok.SneakyThrows;
import net.sf.json.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import xzy.dao.GradeMapper;
import xzy.pojo.Grade;
import xzy.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "Grade_delete_Servlet")
public class Grade_delete_Servlet extends HttpServlet {
    Grade grade=new Grade();
    private static ApplicationContext context=new ClassPathXmlApplicationContext("application.xml");
    GradeMapper gradeMapper= (GradeMapper) context.getBean("gradeMapper");
    @SneakyThrows
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String delIds=request.getParameter("delIds");
        JSONObject result=new JSONObject();
        List<Object> listNumbers=new ArrayList<Object>();
        int delNums=0;
        delNums=gradeMapper.gradeDelete(delIds);
        if(delNums>0){
            result.put("success", "成功");
            result.put("delNums", delNums);
        }else{
            result.put("errorMsg", "删除失败");
        }
        ResponseUtil.write(response, result);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
